function pageinfo() {//生产计划管理里面的创建新的新的生产计划
    $("#MyTable").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/scjhglshowsc",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                pageNum:(params.offset/params.limit)+1,
            }
        },
        columns:[
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名称",field:"productName",align:"center"},
            {title:"用途",field:"gender",align:"center"},
            {title:"单位",field:"amountUnit",align:"center"},
            {title:"单价",field:"realCostPrice",align:"center"},
            {title:"操作",field:"productId",align:"center",
                formatter:function (value,row,index) {
                let goods=JSON.stringify(row)
                    let btn1="<button onclick=showModel("+goods+") class='btn btn-sm btn-warning'>生产</button>"
                    return btn1
                }
            },
        ]
    })
}
function querysta() {
    $("#mytable").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querysta",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit
            }
        },
        columns:[
            {title:"生产编号",field:"applyId",align:"center"},
            {title:"计划定制人",field:"designer",align:"center"},
            {title:"登记人",field:"register",align:"center"},
            {title:"登记时间",field:"registerTime",align:"center"},
            {title:"备注",field:"remark",align:"center"},
            {title:"审核",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                var b="";
                    if (value=="S001-0"){
                      b="<button onclick='addscpgd()'></button>"
                    }else if (value=="S001-1"){
                        b="通过"
                    }else {
                        b="未通过"
                    }
                    return b;
                }
            },
        ]
    })
}
function queryMPS() {
    $("#mytable").bootstrapTable({//查询所有的生产计划单
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querymps",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit
            }
        },
        columns:[
            {title:"计划单编号",field:"applyId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"描述",field:"productDescribe",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"操作",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=generateadispatchorder("+goods+") class='btn btn-sm btn-warning'>生产派工单</button>"
                    return btn1
                }
            },
        ]
    })
}
function productionplan() {
    $("#MyTable").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/scjhshquerystate",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit
            }
        },
        columns:[
            {title:"生产编号",field:"applyId",align:"center"},
            {title:"计划定制人",field:"designer",align:"center"},
            {title:"登记人",field:"register",align:"center"},
            {title:"登记时间",field:"registerTime",align:"center"},
            {title:"备注",field:"remark",align:"center"},
            {title:"审核",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=querydetail("+goods+") class='btn btn-sm btn-warning'>审核</button>"
                    return btn1
                }
            },
        ]
    })
}
function proeandmxxxx() {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querybyid",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /*pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit,*/
                parentId:$("#id").val()//

            }
        },
        columns:[
            {title:"工序编号",field:"id",align:"center"},
            {title:"工序名称",field:"procedureName",align:"center"},
            {title:"描述",field:"register",align:"center"},
            {title:"工时数",field:"labourHourAmount",align:"center"},
            {title:"单位工时成本",field:"subtotal",align:"center"},
           /* {title:"工时完成小计",field:"remark",align:"center"},*/
            {title:"查看物料",field:"id",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=querymaterial("+value+") class='btn btn-sm btn-warning'>登记</button>"
                    return btn1
                }
            },
        ]
    })
}
function dispatchordequeryr() {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scpg/querybysta",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
               /* /!*pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit,*!/
                parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"生产派工单编号",field:"manufactureId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"登记时间",field:"checkTime",align:"center"},
            /* {title:"工时完成小计",field:"remark",align:"center"},*/
            {title:"审核",field:"id",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=queryerview("+goods+") class='btn btn-sm btn-warning'>审核</button>"
                    return btn1
                }
            },
        ]
    })
}
function queryproduceandproduction() {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scpg/queryproduceandproductions",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"派工单编号",field:"manufactureId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"投产数量",field:"demandAmount",align:"center"},
            {title:"合格数量",field:"realAmount",align:"center"},
          //  {title:"派工状态",field:"checkTime",align:"center"},
            {title:"审核状态",field:"checkTag",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let v="";
                    if (value=="S001-0"){
                        v="等待审核"
                    }
                    if (value=="S001-1"){
                        v="通过"
                    }
                    if (value=="S001-2"){
                        v="不通过"
                    }
                    let ab="<a onclick='ck("+goods+")'>"+v+"</a>";
                    return ab;
                }
            },
         //   {title:"生产状态",field:"checkTime",align:"center",}不知道生产状态是哪个列
            /* {title:"工时完成小计",field:"remark",align:"center"},*/

        ]
    })
    ck=function (goods) {
        //把id换成goods里面的值就好了
        var s = JSON.stringify($("#designer").val())
        localStorage.setItem("designer", s);
        var s1 = JSON.stringify($("#register").val())
        localStorage.setItem("register", s1);
        var s2 = JSON.stringify($("#productId").val())
        localStorage.setItem("productId", s2);
        var s3 = JSON.stringify($("#productName").val())
        localStorage.setItem("productName", s3);
        var s4 = JSON.stringify($("#amount").val())
        localStorage.setItem("amount", s4);
        var s5 = JSON.stringify($("#productDescribe").val())
        localStorage.setItem("productDescribe", s5);
        var s6 = JSON.stringify($("#id").val())
        localStorage.setItem("id", s6);
        location.href="querydatil.html"
    }
}//Productionregistration  Productionregistrationreview
function dispatchordequeryr() {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scpg/querybysta",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"生产派工单编号",field:"manufactureId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"登记时间",field:"checkTime",align:"center"},
            /* {title:"工时完成小计",field:"remark",align:"center"},*/
            {title:"审核",field:"id",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=queryerview("+goods+") class='btn btn-sm btn-warning'>审核</button>"
                    return btn1
                }
            },
        ]
    })
}
function Productionregistration(goods) {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querymps",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"计划单编号",field:"applyId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"描述",field:"productDescribe",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"操作",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=dj("+goods+") class='btn btn-sm btn-warning'>登记</button>"
                    return btn1
                }
            },
        ]
    })
    dj=function (goods) {
        //把值放浏览器里面
        location.href="query.html"
    }
}
function registration(goods) {//这个才对
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querybyid",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /*pageNum:(params.offset/params.limit)+1,
                pageSize:params.limit,*/
                parentId:$("#id").val()//

            }
        },
        columns:[
            {title:"工序编号",field:"id",align:"center"},
            {title:"工序名称",field:"procedureName",align:"center"},
            {title:"描述",field:"register",align:"center"},
            {title:"工时数",field:"labourHourAmount",align:"center"},
            {title:"单位工时成本",field:"subtotal",align:"center"},
            /* {title:"工时完成小计",field:"remark",align:"center"},*/
            {title:"登记",field:"manufactureProcedureTag",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)//S002-0
                    let btn1="";
                    if (value=="S002-0"){
                        btn1="<a onclick=dj("+value+") class='btn btn-sm btn-warning'>登记</a>"
                    }else {
                        btn1="<a>以登记</a>"
                    }

                    return btn1
                }
            },
        ]
    })
    dj=function (goods) {
        location.href="assemble.html";
       /* $*/
    }
}
function Productionregistrationreview(goods) {//ScdjController
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scdj/queryr",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"计划单编号",field:"applyId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"描述",field:"productDescribe",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"操作",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=dj("+goods+") class='btn btn-sm btn-warning'>复核登记</button>"
                    return btn1
                }
            },
        ]
    })
    dj=function (goods) {
        // 之后换活的的值
       /* $("#designer").val("designer");
        $("#register").val("register");
        $("#productId").val("productId");
        $("#productName").val("productName");
        $("#amount").val("amount")
        $("#productDescribe").val("productDescribe")
        $("#id").val("生产计划单编号")*/
        location.href="queryfhdj.html"
    }
}
function Productionregistrations(goods) {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scjh/querymps",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"计划单编号",field:"applyId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"描述",field:"productDescribe",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"操作",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=dj("+goods+") class='btn btn-sm btn-warning'>登记</button>"
                    return btn1
                }
            },
        ]
    })
    dj=function (goods) {
        //把值放浏览器里面
        location.href="examine.html"
    }
}
function Productionregistrationview(goods) {
    $("#tab").bootstrapTable({
        method:"post",
        contentType: 'application/json',
        url:"../scdj/view",
        striped:true,
        pageNumber:1,
        pageSize:5,
        // 是否分页
        pagination:true,
        sidePagination: "server",
        pageList:[3,4,5],
        queryParams:function (params) {
            return{
                /* /!*pageNum:(params.offset/params.limit)+1,
                 pageSize:params.limit,*!/
                 parentId:$("#id").val()//*/

            }
        },
        columns:[
            {title:"派工单编号",field:"manufactureId",align:"center"},
            {title:"产品编号",field:"productId",align:"center"},
            {title:"产品名",field:"productName",align:"center"},
            {title:"数量",field:"amount",align:"center"},
            {title:"合格数量",field:"testedAmount",align:"center"},
            {title:"生产状态",field:"applyId",align:"center",
                formatter:function (value,row,index) {
                    let goods=JSON.stringify(row)
                    let btn1="<button onclick=dj("+goods+") class='btn btn-sm btn-warning'>登记</button>"
                    return btn1
                }
            },
        ]
    })
    dj=function (goods) {
        //把值放浏览器里面
        location.href="view.html"
    }
}





function querydetail(goods) {
    $("#exampleModal").modal("show")
    //死值
    var  tab=$("#mytables");
    $("#scjhid").val("1234567812311")
    $("#register").val("张飒")
   // $("#")权限做好后在弄
   /* $("#MyTr").nextAll().remove();
    var tr=$("<tr><td id='productId'>1231</td><td>zz</td><td>1</td><td>描述</td></tr>")
    tab.append(tr)*/

}

function generateadispatchorder(goods) {
    $("#designer").val("designer");
    $("#register").val("register");
    $("#productId").val("productId");
    $("#productName").val("productName");
    $("#amount").val("amount")
    $("#productDescribe").val("productDescribe")
    $("#id").val("生产计划单编号")
    $("#exampleModal").modal("show")
    //时间你们自己考虑要不要

}



function add() {
    //需要添加的商品
    $("#exampleModal").modal("show")
    var tab=$("#MyTable");
    $("#MyTr").nextAll().remove();
    var tr=$("<tr><td>zz</td><td>1231</td><td><input type='text' value='1'></td><td>15</td>" +
        "<td><span class=\"price\" id=\"price\">￥0.00</span></td>" +
        "<td><a  onclick='showModel()' class='btn-outline-success btn'>生产</a></td></tr>")
    tab.append(tr)
}

function showModel() {
    //点击添加后的商品 goods

    //console.log(goods)
   var tab=$("#cptab");//里面到时候换成变量
    var tr=$("<tr><td><input type='checkbox' value='1' ></td><td><input name='productName' type='hidden' value='zz'>zz</td><td><input type='hidden' name='productId' value='1231'>1231</td>" +
        "<td><input type='number' value='1' name='amount' class='input'></td><td>15</td>" +
        "<td><span class=\"price\">￥0.00</span></td></tr>")
    tab.append(tr)
    tab.bootstrapTable("refresh")
    $(":input[type='number']").blur(function(){
        zongjia()
        xiaoji($(this))
    })
    $("tbody :checkbox").click(function(){
      //  alert("点击")
         zongjia()
       // xiaoji($(this))
        f($(this))
       // show()
        $(this).parent().parent().toggleClass("c")
        //计算总计

    })

}
function f(obj) {
    var price= parseInt(obj.parent().next().next().next().next().html())
  //  console.log("f小计+++++++++++++++++++++++")
  //  console.log(obj.parent().next().next().next().next().html()+"val")
    var num=parseInt(obj.val())
    var xj=parseInt(price*num).toFixed(2)
    //给小计赋值
    obj.parent().next().next().next().next().next().html("￥"+xj)
    console.log(obj.parent().next().next().html()+"小计")
}
function xiaoji(obj){
    //可以试一下用table里面的input框定位又或者给列表的时候给id自增在通过长度取值
    var price= parseInt(obj.parent().next().html())
    console.log("小计+++++++++++++++++++++++")
    console.log(obj.parent().next().html()+"小计input")
    console.log(price)
    var num=parseInt(obj.val())
    var xj=parseInt(price*num).toFixed(2)
    //给小计赋值
    obj.parent().next().next().html("￥"+xj)
    console.log(obj.parent().next().next().html()+"小计")
}
function show(){
    //商品的数量
    var sum= $("tbody :checkbox").length
    //选中商品的数量
    var cksum= $("tbody :checkbox:checked").length
    if(cksum!=0 && sum==cksum){
        $(":checkbox:first").prop("checked",true)
    }else{
        $(":checkbox:first").prop("checked",false)
    }
    //计算总计
    zongjia()
}
function zongjia(){
    //alert("调用了")
    var sumnum=0;
    var sumprice=0;
    var price=0;
    $("tbody :checkbox:checked").each(function(i,e){
        sumnum+=parseInt($(e).parent().next().next().next().find(":input").val())
        price=$(e).parent().parent().find("td:eq(4)").html()

    })
    sumprice=parseFloat(price*sumnum)
    console.log(sumnum+"总数")
    console.log(sumprice+"总计")
    //$("#span").html(sumnum)
    console.log($("#price").val()+"价格")
    $("#price").html("￥"+sumprice.toFixed(2))
}
$("#check").click(function(){
    alert($("tbody :checkbox").length)
    //checkbox是否全选
    var zt=$(this).prop("checked")
    $("tbody :checkbox").prop("checked",zt)
    //颜色是否全选
    if(zt==true){
        $("tbody tr").addClass("c")
    }else{
        $("tbody tr").removeClass("c")
    }
    //计算
    zongjia()
})
function del(id) {
    if(confirm("您确认要删除吗?")){
        $.post("/Emp/delete", {"id": id}, function (data) {
            alert(data.msg);
            if (data.code == "1") {
                //表单刷新 bootstrapTable提供刷新或重新加载
                $("#MyTable").bootstrapTable("refresh")
            }
        }, "json");
    }
}

// Example starter JavaScript for disabling form submissions if there are invalid fields
/*
(function() {
    window.addEventListener('load', function() {
        // Fetch all the forms we want to apply custom Bootstrap validation styles to
        var forms = document.getElementsByClassName('needs-validation');
        // Loop over them and prevent submission
        var validation = Array.prototype.filter.call(forms, function(form) {
            form.addEventListener('submit', function(event) {
                if (form.checkValidity() === false) {
                    event.preventDefault();
                    event.stopPropagation();
                }
                form.classList.add('was-validated');
            }, false);
        });
    }, false);
})();*/
